package com.property.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.property.pojo.Building;
import com.property.service.BuildingServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("building")
public class BuildingController {
    @Autowired
    private BuildingServer buildingServer;

    //查询所有的楼房信息
    @RequestMapping("findAllBuilding")
    public String findAllBuilding(){
        return JSON.toJSONString(buildingServer.findAllBuilding());
    }

    //查询所有的楼房和住户
    @RequestMapping("findAll")
    public String findAll(Integer page){
        return buildingServer.findAllBuildingResident(page);
    }
    //新增房屋
    @RequestMapping("saveBuilding")
    public String saveBuilding(Building building){
        return buildingServer.saveBuilding(building);
    }
    //根据id查询房屋
    @RequestMapping("findBuildBybId")
    public String findBuildBybId(Integer bId){
        return JSON.toJSONString(buildingServer.findBuildingBybId(bId));
    }
    //删除房屋信息
    @RequestMapping("deleteBuilding")
    public String deleteBuilding(Integer bId){
        int num = buildingServer.deleteBuilding(bId);
        return JSON.toJSONString((num > 0) ? "操作成功":"操作失败");
    }
}
